1 import java.awt.*;
2 import java.awt.event.*;
3 import java.util.*;
4
5 public class MasterUI implements ActionListener {
6
7 // Public constants
8 public final static int numberOfSlaves = 10;
9
10 public final static int statusGray = 0;
11 public final static int statusRed = 1;
12 public final static int statusOrange = 2;
13 public final static int statusGreen = 3;
14
15 // Private var members ------------------------------------------------------
16
17 // Private UI geometry constants
18 private final static int sTextSize = 50;
19 private final static int sTextSizeStatus = 15;
20 private final static int sTimeSize = 12;
21 private final static int sFrameSizeX = 700;
22 private final static int sFrameSizeY = 758;
23 private final static int sListGap = 0;
24
25 // Private vars
26 Color cRed;
27 Color cGreen;
28 Color cGray;
29 Color cOrange;
30
31 MEventQueue myEvents;
32
33 // UI Elements
34 Frame f;
35
36 Panel slaveListPanel1[];
37 Label slaveListLabel1[];
38 TextField slaveListStatus[];
39 TextField slaveListTargets[];
40 TextField slaveListUser[];
41 Panel slaveListPanel2[];
42 Checkbox slaveListEnable2[];
43 TextField slaveListScripts[];
44
45
46 TextArea screenLog;
47 Panel panelButton;
48
49 Panel top;
50 Panel list;
51 Panel bottom;
52
53 TextField topStatus;
54 TextField topTime;
55
56 Button bStart;
57 Button bStop;
58 Button bRefresh;
59 Button bPause;
60 TextField testMachine;
61
62 private Color[] colorStatusTable;
63
64
65 MasterUI(Frame f) {
66
67 initialize(f);
68 }
69
70 private void initialize(Frame f) {
71
72 // create colors for the UI components
73 Color cList1 = new Color(186, 210, 214);
74 Color cList2 = new Color(239, 228, 238);
75
76 colorStatusTable = new Color[statusGreen+1];
77 colorStatusTable[statusRed] = new Color(221, 164, 155);
78 colorStatusTable[statusGreen] = new Color(203, 225, 198);
79 colorStatusTable[statusGray] = new Color(225, 226, 224);
80 colorStatusTable[statusOrange] = new Color(253, 235, 208);
81
82 this.f = f;
83 f.setLayout(new BorderLayout());
84 f.setTitle("JF Performance Test Tool - MASTER");
85
86 // Build main Panels
87 top = new Panel();
88 top.setLayout(new BorderLayout());
89
90 list = new Panel();
91 GridLayout listLayout = new GridLayout(20,1);
92 listLayout.setVgap(sListGap);
93 list.setLayout(listLayout);
94
95 bottom = new Panel();
96 bottom.setLayout(new BorderLayout());
97
98 // Build top and add to top panel
99 topStatus = new TextField("Started!");
100 topStatus.setEditable(false);
101 topTime = new TextField("0", sTimeSize);
102 topTime.setEditable(false);
103 top.add(topStatus, "Center");
104 top.add(topTime, "East");
105
106 // Build slave lists and add to list panel
107 int i;
108 slaveListPanel1 = new Panel[numberOfSlaves];
109 slaveListLabel1 = new Label[numberOfSlaves];
110 slaveListStatus = new TextField[numberOfSlaves];
111 slaveListTargets = new TextField[numberOfSlaves];
112 slaveListPanel2 = new Panel[numberOfSlaves];
113 slaveListEnable2 = new Checkbox[numberOfSlaves];
114 slaveListScripts = new TextField[numberOfSlaves];
115 slaveListUser = new TextField[numberOfSlaves];
116
117 boolean cT = false;
118
119 for (i = 0; i < numberOfSlaves; i++) {
120
121 slaveListPanel1[i] = new Panel();
122 slaveListPanel1[i].setLayout(new FlowLayout(FlowLayout.LEFT));
123 slaveListLabel1[i] = new Label(" " + i + " ");
124 slaveListStatus[i] = new TextField("NONE", sTextSizeStatus);
125 slaveListStatus[i].setBackground(cGray);
126 slaveListStatus[i].setEditable(false);
127 slaveListTargets[i] = new TextField("no target", sTextSize);
128 slaveListUser[i] = new TextField("1", 8);
129 slaveListPanel1[i].add(slaveListLabel1[i]);
130 slaveListPanel1[i].add(slaveListStatus[i]);
131 slaveListPanel1[i].add(slaveListTargets[i]);
132 slaveListPanel1[i].add(slaveListUser[i]);
133
134 slaveListPanel2[i] = new Panel();
135 slaveListPanel2[i].setLayout (new FlowLayout(FlowLayout.LEFT));
136 slaveListPanel1[i].setBackground(Color.green);
137 slaveListEnable2[i] = new Checkbox("enable .", false);
138 slaveListScripts[i] = new TextField("no script", sTextSize);
139 slaveListPanel2[i].add(slaveListEnable2[i]);
140 slaveListPanel2[i].add(slaveListScripts[i]);
141
142 if ( cT == true ) {
143 slaveListPanel1[i].setBackground(cList1);
144 slaveListPanel2[i].setBackground(cList1);
145 cT = false;
146 } else {
147 slaveListPanel1[i].setBackground(cList2);
148 slaveListPanel2[i].setBackground(cList2);
149 cT = true;
150 }
151
152 list.add(slaveListPanel1[i]);
153 list.add(slaveListPanel2[i]);
154
155 }
156
157 // Build bottom
158 panelButton = new Panel();
159 bStart = new Button("Start");
160 bStop = new Button("Stop");
161 bRefresh = new Button("Refresh");
162 bPause = new Button("Pause");
163 testMachine = new TextField("Test machine", 20);
164
165 panelButton.setLayout(new FlowLayout(FlowLayout.LEFT));
166 panelButton.add(bStart);
167 panelButton.add(bStop);
168 panelButton.add(bRefresh);
169 panelButton.add(bPause);
170 panelButton.add(testMachine);
171 bStart.addActionListener(this);
172 bStop.addActionListener(this);
173 bRefresh.addActionListener(this);
174 bPause.addActionListener(this);
175
176 screenLog = new TextArea(6, 80);
177 screenLog.setEditable(false);
178
179 bottom.add(screenLog, "Center");
180 bottom.add(panelButton, "South");
181
182 // Complete the frame
183 f.add(top, "North");
184 f.add(list, "Center");
185 f.add(bottom, "South");
186
187 f.setSize(sFrameSizeX,sFrameSizeY);
188 f.show();
189
190 }
191
192 public void actionPerformed(ActionEvent e) {
193
194 Object source = e.getSource();
195 String ac = e.getActionCommand();
196
197 if ( source == bStart) {
198 pushEvent(MEvent.eventUI_START, 0);
199
200 } else if ( source == bStop) {
201 pushEvent(MEvent.eventUI_STOP, 0);
202
203 } else if ( source == bRefresh) {
204 pushEvent(MEvent.eventUI_REFRESH, 0);
205
206 } else if ( source == bPause) {
207 pushEvent(MEvent.eventUI_PAUSE, 0);
208
209 } else {
210 System.out.println("Software Detected Fault : MasterUI.actionPerformed. Unknown event source.\n");
211 System.out.println("---> ac = " + ac + "\n");
212 }
213 }
214
215 private void pushEvent(int eventCode, int index) {
216
217 MEvent anEvent = new MEvent();
218
219 anEvent.event = eventCode;
220 anEvent.value = index;
221
222 myEvents.put(anEvent);
223
224 }
225
226
227 // ----- PUBLIC API ----------------------------------------------
228
229 public void putScreenLog(String entry) {
230 screenLog.append(entry + "\n");
231 }
232
233 public void setStatus(String text, int color) {
234 topStatus.setBackground(colorStatusTable[color]);
235 topStatus.setText(text);
236 }
237
238 public void setSlaveStatus(String text, int color, int slot) {
239 slaveListStatus[slot].setBackground(colorStatusTable[color]);
240 slaveListStatus[slot].setText(text);
241 }
242
243 public void clearTarget(int slot) {
244 slaveListTargets[slot].setText("no target");
245 }
246
247 public String getTarget(int slot) {
248 return slaveListTargets[slot].getText();
249 }
250
251 public int getUser(int slot) {
252 int n;
253 try {
254 n= Integer.parseInt(slaveListUser[slot].getText());
255 return n;
256 } catch (Exception e) {return 0;}
257 }
258
259 public void clearScript(int slot) {
260 slaveListScripts[slot].setText("no script");
261 }
262
263 public String getScript(int slot) {
264 return slaveListScripts[slot].getText();
265 }
266
267 public String getTestMachine() {
268 return testMachine.getText();
269 }
270
271 public boolean isEnabled(int slot) {
272 return slaveListEnable2[slot].getState();
273 }
274
275 public void register(MEventQueue aQueue) {
276 myEvents = aQueue;
277 }
278
279 }
|